package part.a;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class EchoServer {

	public static void main(String[] args) {
		try {
			ServerSocket socket = new ServerSocket(6969);
			DataInputStream input;
			DataOutputStream output;

			byte[] buffer = new byte[1024];
			int bytesRead;

			while (true) {

				Socket client = socket.accept();
				input = new DataInputStream(client.getInputStream());
				output = new DataOutputStream(client.getOutputStream());
				bytesRead = input.read(buffer);

				while (bytesRead != -1) {
					output.write(buffer, 0, bytesRead);
					bytesRead = input.read(buffer);
				}

				client.close();
			}

		} catch (IOException ioe) {
			System.err.println(ioe);
		}
	}
}
